#define _CRT_SECURE_NO_WARNINGS 1
#pragma warning(disable:6031)


//https://leetcode.cn/problems/minimum-size-subarray-sum/
class Solution {
public:
    int minSubArrayLen(int target, vector<int>& nums) {
        int left = 0, right = 0;
        int sum = nums[right], len = 0;
        while (right < nums.size())
        {
            if (sum < target)
            {
                right++;
                if (right < nums.size())
                    sum += nums[right];
            }
            else
            {
                if (len > right - left + 1 || len == 0)
                    len = right - left + 1;

                while (sum >= target)
                {
                    sum -= nums[left++];

                    if (sum >= target && len > right - left + 1)
                    {
                        len--;
                    }

                }
            }
        }
        return len;
    }
};